﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DC2010;
using DC2010.Systems;
using DC2010.Objects;
using DC2010.Tools;
using System.IO;
using DC2010.Effects;

namespace DC2010_Editor
{
    public partial class ChooseBasedOn : Form
    {
        public string ChosenAncessor { get; set; }

        private string ss;
        public ChooseBasedOn(string s) 
        {
            InitializeComponent();
            this.ss = s;
            ChosenAncessor = "";
        }

        private void ChooseBasedOn_Load(object sender, EventArgs e)
        {
            if (ss == "Item")
            {
                foreach (Item i in Root.I.ItemSystem.List)
                {

                        ImageListBoxItem itm = new ImageListBoxItem(i.Info.Id);
                        Image img = Properties.Resources.page;

                        //if (i.Gfx.Icon != null)
                        //{
                        //    img = GetImage(i.Gfx.Icon);
                        //}

                        itm.Image = img;
                        imageListBox1.Items.Add(itm);
                    
                }
            }

            if (ss == "Effect")
            {
                foreach (Effect i in Root.I.EffectSystem.List)
                {

                    ImageListBoxItem itm = new ImageListBoxItem(i.Info.Id);
                    Image img = Properties.Resources.page;

                    //if (i.Gfx.Icon != null)
                    //{
                    //    img = GetImage(i.Gfx.Icon);
                    //}

                    itm.Image = img;
                    imageListBox1.Items.Add(itm);

                }
            }

            if (ss == "Creature")
            {
                foreach (Creature i in Root.I.CreatureSystem.List)
                {

                    ImageListBoxItem itm = new ImageListBoxItem(i.Info.Id);
                    Image img = Properties.Resources.page;

                    itm.Image = img;
                    imageListBox1.Items.Add(itm);

                }
            }

            if (ss == "Party")
            {
                foreach (Party i in Root.I.PartySystem.List)
                {

                    ImageListBoxItem itm = new ImageListBoxItem(i.Info.Id);
                    Image img = Properties.Resources.page;

                    itm.Image = img;
                    imageListBox1.Items.Add(itm);

                }

            }

            crystalButton5.Enabled = false;
        }

        private Image GetImage(string partialPath)
        {
            string s = Environment.CurrentDirectory + "\\Gfx\\" + partialPath + ".png";
            if (File.Exists(s))
            {
                return Image.FromFile(s);
            }

            return null;
        }

        private void imageListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            crystalButton5.Enabled = true;

            if (imageListBox1.SelectedItem != null)            
            {
                ImageListBoxItem itm = (ImageListBoxItem)imageListBox1.SelectedItem;
                ChosenAncessor = itm.Text;
                label2.Text = ChosenAncessor;
            }

        }

        private void crystalButton5_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
